import {AsyncController, TaskList} from "../lib/index.ts";

// 用于生成异步任务
function createTestTask(length = 10): TaskList {
    const result = [];
    for (let i = 0; i < length; i++) {
        result.push(
            () => new Promise((resolve, reject) => {
                console.log("start", i);
                setTimeout(() => {
                    console.log(i);
                    if (i % 2 === 0) {
                        resolve(i)
                    } else {
                        reject(i)
                    }
                }, Math.floor(Math.random() * (2000 - 1000 + 1)) + 2000)
            }))
    }
    return result
}

// 实例化控制器
const controller = new AsyncController(createTestTask(20), 3);
// 开始执行任务
controller.startTask().then(result => {
    console.log(result)
});